package com.luych.toolbox.docker.service.sdk.image.model;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class DockerImagesPruneResult {

    @JsonProperty("SpaceReclaimed")
    private Long spaceReclaimed;

    @JsonProperty("ImagesDeleted")
    private List<ImageDelete> imagesDeleted;

    public Long getSpaceReclaimed() {
        return spaceReclaimed;
    }

    public void setSpaceReclaimed(Long spaceReclaimed) {
        this.spaceReclaimed = spaceReclaimed;
    }

    public List<ImageDelete> getImagesDeleted() {
        return imagesDeleted;
    }

    public void setImagesDeleted(List<ImageDelete> imagesDeleted) {
        this.imagesDeleted = imagesDeleted;
    }

    @Override
    public String toString() {
        if (imagesDeleted == null || imagesDeleted.isEmpty()) return "";
        return imagesDeleted.stream().map(Objects::toString).collect(Collectors.joining("\r\n"));
    }

    public static class ImageDelete {

        @JsonProperty("Deleted")
        private String deleted;

        @JsonProperty("Untagged")
        private String untagged;

        public String getDeleted() {
            return deleted;
        }

        public void setDeleted(String deleted) {
            this.deleted = deleted;
        }

        public String getUntagged() {
            return untagged;
        }

        public void setUntagged(String untagged) {
            this.untagged = untagged;
        }

        @Override
        public String toString() {
            if (deleted != null) {
                return "deleted: " + deleted;
            } else if (untagged != null) {
                return "untagged: " + untagged;
            } else {
                return "";
            }
        }
    }
}